import React, { useRef, useState, useEffect } from 'react';
import { connect } from 'umi';
import TableDataBlock from '@/components/TableDataBlock';
import { reloadTab } from '@/utils/utils';
import { notification } from 'antd';
import { Button, Modal, Space, Form, Row, Col } from 'antd';
import { workType_status_selece } from '@/common/contact';
import FormCondition from '@/components/FormCondition';
import aliOssUpload from '@/utils/aliOssUpload';
import { useUpdateEffect } from 'ahooks';
const AuthFormSetting = (props) => {
  const {
    visible = {},
    onClose,
    loading,
    dispatch,
    handleCallback
  } = props;
  console.log(visible)
  const { show = false, detail = {}, } = visible;
  const { id, stage } = detail
  const [form] = Form.useForm();
  const formItems = [
    {
      label: '关联类型',
      name: 'workType',
      select: workType_status_selece,
      type: 'radio'
    },
    {
      label: '申请说明',
      name: 'applyContent',
      type: 'textArea',
      rules: [{ required: false }],
    },
    {
      label: '图片',
      name: 'applyImages',
      type: 'upload',
      rules: [{ required: false }],
    },
    // {
    //   label: '附件',
    //   name: 'applyAttachments',
    //   type: 'otherUpload'
    // },
  ];
  const handleUpAudit = () => {
    form.validateFields().then(async (values) => {
      const { applyImages } = values
      const img = await aliOssUpload(applyImages)
      dispatch({
        type: 'subscriber/fakePreUserStageAdminApply',
        payload: {
          organizationUserId: id,
          stage,
          ...values,
          applyImages: img.toString(),

        },
        callback: (e) => {
          onClose()
          handleCallback && handleCallback()
        }
      })
    });

  };

  const modalProps = {
    title: `发起申请`,
    width: 900,
    visible: show,
    maskClosable: true,
    destroyOnClose: true,
    zIndex: 1001,
    confirmLoading: loading,
    footer: <Space>
      <Button onClick={() => onClose()}>取消</Button>
      <Button type='primary' onClick={() => handleUpAudit()}>确定</Button>
    </Space>
  };

  return (
    <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
      <FormCondition initialValues={detail} form={form} formItems={formItems}></FormCondition>
    </Modal>
  );
};

export default connect(({ weCom, loading }) => ({
  ...weCom,
  loading: loading.models.weCom || loading.models.subscriber,
}))(AuthFormSetting);
